use dataset,clear
ssc inst _gwtmean, replace
set more off
destring D*, replace force

//RECODE SOCIO-DEMOGRPHICS
//age
drop age
gen age = 2014-birth
recode age (17/29 = 1) (30/44 =2) (45/64=3) (65/100 =4), gen(agefour)
//gender
encode gender, gen (sex)
//income
encode income,gen(n_income)
recode n_i  (27 28 40 47 48 49 =0 "NA") (41 1 44 65 45 70 43 38 29 50 61 51 53 42 18 = 1 "Less than 20") (6 9 11 73 74 75 31 32 33 34 35 55 56 57 58 59 60 19 20 21= 2 "20-50") (12 14 15 16 76 77 78 79 80 81 36 37 39 62 63 64 22 23 24 25 26 = 3 "50-100") (2 3 4 5 7 8 10 13 46 66 67 68 69 71 72 30 52 54 17 = 4 "More than 100"), gen(income4)  
recode n_i (27 28 40 47 48 49 =.) (41 44 45 43 50 61 42 = 1) (1 65 70 38 51 18 =2) ( 6 73 29 53 19 =3) (9 74 31 55  20 =4) (11 75 32 56 21 =5) (12 76 33 57 58 =6) (14 77 34 59 60 22=7) (15 78 35 62 23 =8) (16 79 80 81 36 63 24 =9) (2 66 67 37 64 25=10) (3 68 69 39 52 26=11) (4 5 7 8 10 13 46 72 71 30 54 17 =12), gen(incomelev)
//education
encode education,gen(n_education)
encode voca,gen(n_voca)
recode n_e (32 28 33 9 41 5 14 58 34 37 8 10 11 12 59 43= 1 "No HS") (24 15 16 6 42 22 56 57 23 21 7 45 46= 2 "HS") (48 25 49 50= 3 "Some coll") (1 26 4 3 30 47 13 44 53 35 36 = 4 "I_Uni") (2 27 17 29 51 54= 5 "II_Uni") (39 20 18 38 52 55= 6 "Postuni") (31 19 40=.), gen(educlev)
recode educlev (4=5) if country=="GER" & n_voca==5

//RECODE PTVs	   
	   foreach var in  PTVFUT_1 PTVFUT_2 PTVFUT_3 PTVFUT_4 PTVFUT_5 PTVFUT_6 PTVFUT_7 PTVFUT_8 PTVFUT_9 {
	 gen `var'01= .
	 replace `var'01=1 if `var'== "Always" 
	 replace `var'01=.75 if `var'=="Most of the time"  
	 replace `var'01=.5 if `var'=="About half the time"  
	 replace `var'01=.25 if `var'=="Occasionally"  
	 replace `var'01=0 if `var'=="Never" 
}
rename PTVFUT_101 ptv1 
rename PTVFUT_201 ptv2  
rename PTVFUT_301 ptv3   
rename PTVFUT_401 ptv4  
rename PTVFUT_501 ptv5  
rename PTVFUT_601 ptv6  
rename PTVFUT_701 ptv7  
rename PTVFUT_801 ptv8  
*rename PTVFUT_901 ptv9  

//remove case with all missing values
drop if case==312217335 & partyorder==.

//unify missing on issues
replace C1_1_a = "NA" if C1_1_a=="[998]Skipped" | C1_1_a=="[999]Not Asked"
replace C1_1_b = "NA" if C1_1_b=="[998]Skipped" | C1_1_b=="[999]Not Asked"
replace C1_1_c = "NA" if C1_1_c=="[998]Skipped" | C1_1_c=="[999]Not Asked"
replace C1_1_d = "NA" if C1_1_d=="[998]Skipped" | C1_1_d=="[999]Not Asked"
replace C1_1_e = "NA" if C1_1_e=="[998]Skipped" | C1_1_e=="[999]Not Asked"
replace C1_1_f = "NA" if C1_1_f=="[998]Skipped" | C1_1_f=="[999]Not Asked"
replace C1_1_g = "NA" if C1_1_g=="[998]Skipped" | C1_1_g=="[999]Not Asked"
replace C1_1_h = "NA" if C1_1_h=="[998]Skipped" | C1_1_h=="[999]Not Asked"
replace C1_1_i = "NA" if C1_1_i=="[998]Skipped" | C1_1_i=="[999]Not Asked"
replace C1_2_a = "NA" if C1_2_a=="[998]Skipped" | C1_2_a=="[999]Not Asked"
replace C1_2_b = "NA" if C1_2_b=="[998]Skipped" | C1_2_b=="[999]Not Asked"
replace C1_2_c = "NA" if C1_2_c=="[998]Skipped" | C1_2_c=="[999]Not Asked"
replace C1_2_d = "NA" if C1_2_d=="[998]Skipped" | C1_2_d=="[999]Not Asked"
replace C1_2_e = "NA" if C1_2_e=="[998]Skipped" | C1_2_e=="[999]Not Asked"
replace C1_2_f = "NA" if C1_2_f=="[998]Skipped" | C1_2_f=="[999]Not Asked"
replace C1_2_g = "NA" if C1_2_g=="[998]Skipped" | C1_2_g=="[999]Not Asked"
replace C1_2_h = "NA" if C1_2_h=="[998]Skipped" | C1_2_h=="[999]Not Asked"
replace C1_2_i = "NA" if C1_2_i=="[998]Skipped" | C1_2_i=="[999]Not Asked"
replace C1_3_a = "NA" if C1_3_a=="[998]Skipped" | C1_3_a=="[999]Not Asked"
replace C1_3_b = "NA" if C1_3_b=="[998]Skipped" | C1_3_b=="[999]Not Asked"
replace C1_3_c = "NA" if C1_3_c=="[998]Skipped" | C1_3_c=="[999]Not Asked"
replace C1_3_d = "NA" if C1_3_d=="[998]Skipped" | C1_3_d=="[999]Not Asked"
replace C1_3_e = "NA" if C1_3_e=="[998]Skipped" | C1_3_e=="[999]Not Asked"
replace C1_3_f = "NA" if C1_3_f=="[998]Skipped" | C1_3_f=="[999]Not Asked"
replace C1_3_g = "NA" if C1_3_g=="[998]Skipped" | C1_3_g=="[999]Not Asked"
replace C1_3_h = "NA" if C1_3_h=="[998]Skipped" | C1_3_h=="[999]Not Asked"
replace C1_3_i = "NA" if C1_3_i=="[998]Skipped" | C1_3_i=="[999]Not Asked"
replace C1_4_a = "NA" if C1_4_a=="[998]Skipped" | C1_4_a=="[999]Not Asked"
replace C1_4_b = "NA" if C1_4_b=="[998]Skipped" | C1_4_b=="[999]Not Asked"
replace C1_4_c = "NA" if C1_4_c=="[998]Skipped" | C1_4_c=="[999]Not Asked"
replace C1_4_d = "NA" if C1_4_d=="[998]Skipped" | C1_4_d=="[999]Not Asked"
replace C1_4_e = "NA" if C1_4_e=="[998]Skipped" | C1_4_e=="[999]Not Asked"
replace C1_4_f = "NA" if C1_4_f=="[998]Skipped" | C1_4_f=="[999]Not Asked"
replace C1_4_g = "NA" if C1_4_g=="[998]Skipped" | C1_4_g=="[999]Not Asked"
replace C1_4_h = "NA" if C1_4_h=="[998]Skipped" | C1_4_h=="[999]Not Asked"
replace C1_4_i = "NA" if C1_4_i=="[998]Skipped" | C1_4_i=="[999]Not Asked"
replace C2_1_a = "NA" if C2_1_a=="[8]Skipped" | C2_1_a=="[9]Not Asked"
replace C2_1_b = "NA" if C2_1_b=="[8]Skipped" | C2_1_b=="[9]Not Asked"
replace C2_1_c = "NA" if C2_1_c=="[8]Skipped" | C2_1_c=="[9]Not Asked"
replace C2_1_d = "NA" if C2_1_d=="[8]Skipped" | C2_1_d=="[9]Not Asked"
replace C2_1_e = "NA" if C2_1_e=="[8]Skipped" | C2_1_e=="[9]Not Asked"
replace C2_1_f = "NA" if C2_1_f=="[8]Skipped" | C2_1_f=="[9]Not Asked"
replace C2_1_g = "NA" if C2_1_g=="[8]Skipped" | C2_1_g=="[9]Not Asked"
replace C2_1_h = "NA" if C2_1_h=="[8]Skipped" | C2_1_h=="[9]Not Asked"
replace C2_1_i = "NA" if C2_1_i=="[8]Skipped" | C2_1_i=="[9]Not Asked"
replace C2_2_a = "NA" if C2_2_a=="[8]Skipped" | C2_2_a=="[9]Not Asked"
replace C2_2_b = "NA" if C2_2_b=="[8]Skipped" | C2_2_b=="[9]Not Asked"
replace C2_2_c = "NA" if C2_2_c=="[8]Skipped" | C2_2_c=="[9]Not Asked"
replace C2_2_d = "NA" if C2_2_d=="[8]Skipped" | C2_2_d=="[9]Not Asked"
replace C2_2_e = "NA" if C2_2_e=="[8]Skipped" | C2_2_e=="[9]Not Asked"
replace C2_2_f = "NA" if C2_2_f=="[8]Skipped" | C2_2_f=="[9]Not Asked"
replace C2_2_g = "NA" if C2_2_g=="[8]Skipped" | C2_2_g=="[9]Not Asked"
replace C2_2_h = "NA" if C2_2_h=="[8]Skipped" | C2_2_h=="[9]Not Asked"
replace C2_2_i = "NA" if C2_2_i=="[8]Skipped" | C2_2_i=="[9]Not Asked"
replace C2_3_a = "NA" if C2_3_a=="[8]Skipped" | C2_3_a=="[9]Not Asked"
replace C2_3_b = "NA" if C2_3_b=="[8]Skipped" | C2_3_b=="[9]Not Asked"
replace C2_3_c = "NA" if C2_3_c=="[8]Skipped" | C2_3_c=="[9]Not Asked"
replace C2_3_d = "NA" if C2_3_d=="[8]Skipped" | C2_3_d=="[9]Not Asked"
replace C2_3_e = "NA" if C2_3_e=="[8]Skipped" | C2_3_e=="[9]Not Asked"
replace C2_3_f = "NA" if C2_3_f=="[8]Skipped" | C2_3_f=="[9]Not Asked"
replace C2_3_g = "NA" if C2_3_g=="[8]Skipped" | C2_3_g=="[9]Not Asked"
replace C2_3_h = "NA" if C2_3_h=="[8]Skipped" | C2_3_h=="[9]Not Asked"
replace C2_3_i = "NA" if C2_3_i=="[8]Skipped" | C2_3_i=="[9]Not Asked"
replace C2_4_a = "NA" if C2_4_a=="[8]Skipped" | C2_4_a=="[9]Not Asked"
replace C2_4_b = "NA" if C2_4_b=="[8]Skipped" | C2_4_b=="[9]Not Asked"
replace C2_4_c = "NA" if C2_4_c=="[8]Skipped" | C2_4_c=="[9]Not Asked"
replace C2_4_d = "NA" if C2_4_d=="[8]Skipped" | C2_4_d=="[9]Not Asked"
replace C2_4_e = "NA" if C2_4_e=="[8]Skipped" | C2_4_e=="[9]Not Asked"
replace C2_4_f = "NA" if C2_4_f=="[8]Skipped" | C2_4_f=="[9]Not Asked"
replace C2_4_g = "NA" if C2_4_g=="[8]Skipped" | C2_4_g=="[9]Not Asked"
replace C2_4_h = "NA" if C2_4_h=="[8]Skipped" | C2_4_h=="[9]Not Asked"
replace C2_4_i = "NA" if C2_4_i=="[8]Skipped" | C2_4_i=="[9]Not Asked"
replace C3_1a = "NA" if C3_1a=="[8]Skipped" | C3_1a=="Don't Know"
replace C3_1b_1 = "NA" if C3_1b_1=="[8]Skipped" | C3_1b_1=="Don't Know"
replace C3_1b_2 = "NA" if C3_1b_2=="[8]Skipped" | C3_1b_2=="Don't Know"
replace C3_1b_3 = "NA" if C3_1b_3=="[8]Skipped" | C3_1b_3=="Don't Know"
replace C3_1b_4 = "NA" if C3_1b_4=="[8]Skipped" | C3_1b_4=="Don't Know"
replace C3_1b_5 = "NA" if C3_1b_5=="[8]Skipped" | C3_1b_5=="Don't Know"
replace C3_1b_6 = "NA" if C3_1b_6=="[8]Skipped" | C3_1b_6=="Don't Know"
replace C3_1b_7 = "NA" if C3_1b_7=="[8]Skipped" | C3_1b_7=="Don't Know"
replace C3_1b_8 = "NA" if C3_1b_8=="[8]Skipped" | C3_1b_8=="Don't Know"
replace C3_1a = "NA" if C3_1a=="[8]Skipped" | C3_1a=="Don't Know"
replace C3_1b_1 = "NA" if C3_1b_1=="[8]Skipped" | C3_1b_1=="Don't Know"
replace C3_1b_2 = "NA" if C3_1b_2=="[8]Skipped" | C3_1b_2=="Don't Know"
replace C3_1b_3 = "NA" if C3_1b_3=="[8]Skipped" | C3_1b_3=="Don't Know"
replace C3_1b_4 = "NA" if C3_1b_4=="[8]Skipped" | C3_1b_4=="Don't Know"
replace C3_1b_5 = "NA" if C3_1b_5=="[8]Skipped" | C3_1b_5=="Don't Know"
replace C3_1b_6 = "NA" if C3_1b_6=="[8]Skipped" | C3_1b_6=="Don't Know"
replace C3_1b_7 = "NA" if C3_1b_7=="[8]Skipped" | C3_1b_7=="Don't Know"
replace C3_1b_8 = "NA" if C3_1b_8=="[8]Skipped" | C3_1b_8=="Don't Know"
replace C3_2a = "NA" if C3_2a=="[8]Skipped" | C3_2a=="Don't Know"
replace C3_2b_1 = "NA" if C3_2b_1=="[8]Skipped" | C3_2b_1=="Don't Know"
replace C3_2b_2 = "NA" if C3_2b_2=="[8]Skipped" | C3_2b_2=="Don't Know"
replace C3_2b_3 = "NA" if C3_2b_3=="[8]Skipped" | C3_2b_3=="Don't Know"
replace C3_2b_4 = "NA" if C3_2b_4=="[8]Skipped" | C3_2b_4=="Don't Know"
replace C3_2b_5 = "NA" if C3_2b_5=="[8]Skipped" | C3_2b_5=="Don't Know"
replace C3_2b_6 = "NA" if C3_2b_6=="[8]Skipped" | C3_2b_6=="Don't Know"
replace C3_2b_7 = "NA" if C3_2b_7=="[8]Skipped" | C3_2b_7=="Don't Know"
replace C3_2b_8 = "NA" if C3_2b_8=="[8]Skipped" | C3_2b_8=="Don't Know"
replace C3_3a = "NA" if C3_3a=="[8]Skipped" | C3_3a=="Don't Know"
replace C3_3b_1 = "NA" if C3_3b_1=="[8]Skipped" | C3_3b_1=="Don't Know"
replace C3_3b_2 = "NA" if C3_3b_2=="[8]Skipped" | C3_3b_2=="Don't Know"
replace C3_3b_3 = "NA" if C3_3b_3=="[8]Skipped" | C3_3b_3=="Don't Know"
replace C3_3b_4 = "NA" if C3_3b_4=="[8]Skipped" | C3_3b_4=="Don't Know"
replace C3_3b_5 = "NA" if C3_3b_5=="[8]Skipped" | C3_3b_5=="Don't Know"
replace C3_3b_6 = "NA" if C3_3b_6=="[8]Skipped" | C3_3b_6=="Don't Know"
replace C3_3b_7 = "NA" if C3_3b_7=="[8]Skipped" | C3_3b_7=="Don't Know"
replace C3_3b_8 = "NA" if C3_3b_8=="[8]Skipped" | C3_3b_8=="Don't Know"
replace C3_4a = "NA" if C3_4a=="[8]Skipped" | C3_4a=="Don't Know"
replace C3_4b_1 = "NA" if C3_4b_1=="[8]Skipped" | C3_4b_1=="Don't Know"
replace C3_4b_2 = "NA" if C3_4b_2=="[8]Skipped" | C3_4b_2=="Don't Know"
replace C3_4b_3 = "NA" if C3_4b_3=="[8]Skipped" | C3_4b_3=="Don't Know"
replace C3_4b_4 = "NA" if C3_4b_4=="[8]Skipped" | C3_4b_4=="Don't Know"
replace C3_4b_5 = "NA" if C3_4b_5=="[8]Skipped" | C3_4b_5=="Don't Know"
replace C3_4b_6 = "NA" if C3_4b_6=="[8]Skipped" | C3_4b_6=="Don't Know"
replace C3_4b_7 = "NA" if C3_4b_7=="[8]Skipped" | C3_4b_7=="Don't Know"
replace C3_4b_8 = "NA" if C3_4b_8=="[8]Skipped" | C3_4b_8=="Don't Know"
replace C3_5a = "NA" if C3_5a=="[8]Skipped" | C3_5a=="Don't Know"
replace C3_5b_1 = "NA" if C3_5b_1=="[8]Skipped" | C3_5b_1=="Don't Know"
replace C3_5b_2 = "NA" if C3_5b_2=="[8]Skipped" | C3_5b_2=="Don't Know"
replace C3_5b_3 = "NA" if C3_5b_3=="[8]Skipped" | C3_5b_3=="Don't Know"
replace C3_5b_4 = "NA" if C3_5b_4=="[8]Skipped" | C3_5b_5=="Don't Know"
replace C3_5b_5 = "NA" if C3_5b_5=="[8]Skipped" | C3_5b_5=="Don't Know"
replace C3_5b_6 = "NA" if C3_5b_6=="[8]Skipped" | C3_5b_6=="Don't Know"
replace C3_5b_7 = "NA" if C3_5b_7=="[8]Skipped" | C3_5b_7=="Don't Know"
replace C3_5b_8 = "NA" if C3_5b_8=="[8]Skipped" | C3_5b_8=="Don't Know"
replace C3_5a = "Decreased" if C3_5a=="It should become less important" 
replace C3_5b_1 = "Decreased" if C3_5b_1=="It should become less important" 
replace C3_5b_2 = "Decreased" if C3_5b_2=="It should become less important" 
replace C3_5b_3 = "Decreased" if C3_5b_3=="It should become less important" 
replace C3_5b_4 = "Decreased" if C3_5b_4=="It should become less important" 
replace C3_5b_5 = "Decreased" if C3_5b_5=="It should become less important" 
replace C3_5b_6 = "Decreased" if C3_5b_6=="It should become less important" 
replace C3_5b_7 = "Decreased" if C3_5b_7=="It should become less important" 
replace C3_5b_8 = "Decreased" if C3_5b_8=="It should become less important" 
replace C3_5a = "Increased" if C3_5a=="It should become more important" 
replace C3_5b_1 = "Increased" if C3_5b_1=="It should become more important" 
replace C3_5b_2 = "Increased" if C3_5b_2=="It should become more important" 
replace C3_5b_3 = "Increased" if C3_5b_3=="It should become more important" 
replace C3_5b_4 = "Increased" if C3_5b_4=="It should become more important" 
replace C3_5b_5 = "Increased" if C3_5b_5=="It should become more important" 
replace C3_5b_6 = "Increased" if C3_5b_6=="It should become more important" 
replace C3_5b_7 = "Increased" if C3_5b_7=="It should become more important" 
replace C3_5b_8 = "Increased" if C3_5b_8=="It should become more important" 
replace C4_1a = "NA" if C4_1a=="[8]Skipped" | C4_1a=="Don't Know"
replace C4_1b_1 = "NA" if C4_1b_1=="[8]Skipped" | C4_1b_1=="Don't Know"
replace C4_1b_2 = "NA" if C4_1b_2=="[8]Skipped" | C4_1b_2=="Don't Know"
replace C4_1b_3 = "NA" if C4_1b_3=="[8]Skipped" | C4_1b_3=="Don't Know"
replace C4_1b_4 = "NA" if C4_1b_4=="[8]Skipped" | C4_1b_4=="Don't Know"
replace C4_1b_5 = "NA" if C4_1b_5=="[8]Skipped" | C4_1b_5=="Don't Know"
replace C4_1b_6 = "NA" if C4_1b_6=="[8]Skipped" | C4_1b_6=="Don't Know"
replace C4_1b_7 = "NA" if C4_1b_7=="[8]Skipped" | C4_1b_7=="Don't Know"
replace C4_1b_8 = "NA" if C4_1b_8=="[8]Skipped" | C4_1b_8=="Don't Know"

//get to numeric -1/+1 issue placements
encode C1_1_a, gen(C11)
recode C11 (8=.)
encode C1_1_b, gen(C11b)
recode C11b (8=.)
encode C1_1_c, gen(C11c)
recode C11c (8=.)
encode C1_1_d, gen(C11d)
recode C11d (8=.)
encode C1_1_e, gen(C11e)
recode C11e (8=.)
encode C1_1_f, gen(C11f)
recode C11f (8=.)
encode C1_1_g, gen(C11g)
recode C11g (8=.)
encode C1_1_h, gen(C11h)
recode C11h (8=.)
encode C1_1_i, gen(C11i)
recode C11i (8=.)
encode C1_3_a, gen(C13)
recode C13 (8=.)
encode C1_3_b, gen(C13b)
recode C13b (8=.)
encode C1_3_c, gen(C13c)
recode C13c (8=.)
encode C1_3_d, gen(C13d)
recode C13d (8=.)
encode C1_3_e, gen(C13e)
recode C13e (8=.)
encode C1_3_f, gen(C13f)
recode C13f (8=.)
encode C1_3_g, gen(C13g)
recode C13g (8=.)
encode C1_3_h, gen(C13h)
recode C13h (8=.)
encode C1_3_i, gen(C13i)
recode C13i (8=.)
encode C1_4_a, gen(C14)
recode C14 (8=.)
encode C1_4_b, gen(C14b)
recode C14b (8=.)
encode C1_4_c, gen(C14c)
recode C14c (8=.)
encode C1_4_d, gen(C14d)
recode C14d (8=.)
encode C1_4_e, gen(C14e)
recode C14e (8=.)
encode C1_4_f, gen(C14f)
recode C14f (8=.)
encode C1_4_g, gen(C14g)
recode C14g (8=.)
encode C1_4_h, gen(C14h)
recode C14h (8=.)
encode C1_4_i, gen(C14i)
recode C14i (8=.)
encode C2_1_a, gen(C21)
recode C21  (2=-1) (5=1) (1 3 4 =.)
encode C2_1_b, gen(C21b)
recode C21b  (2=-1) (5=1) (1 3 4=.)
encode C2_1_c, gen(C21c)
recode C21c  (2=-1) (5=1) (1 3 4=.)
encode C2_1_d, gen(C21d)
recode C21d  (2=-1) (5=1) (1 3 4=.)
encode C2_1_e, gen(C21e)
recode C21e  (2=-1) (5=1) (1 3 4=.)
encode C2_1_f, gen(C21f)
recode C21f  (2=-1) (5=1) (1 3 4=.)
encode C2_1_g, gen(C21g)
recode C21g  (2=-1) (5=1) (1 3 4=.)
encode C2_1_h, gen(C21h)
recode C21h  (2=-1) (5=1) (1 3 4=.)
encode C2_1_i, gen(C21i)
recode C21i  (2=-1) (5=1) (1 3 4=.)
encode C2_2_a, gen(C22)
recode C22  (2=-1) (5=1) (1 3 4 =.)
encode C2_2_b, gen(C22b)
recode C22b  (2=-1) (5=1) (1 3 4=.)
encode C2_2_c, gen(C22c)
recode C22c  (2=-1) (5=1) (1 3 4=.)
encode C2_2_d, gen(C22d)
recode C22d  (2=-1) (5=1) (1 3 4=.)
encode C2_2_e, gen(C22e)
recode C22e  (2=-1) (5=1) (1 3 4=.)
encode C2_2_f, gen(C22f)
recode C22f  (2=-1) (5=1) (1 3 4=.)
encode C2_2_g, gen(C22g)
recode C22g  (2=-1) (5=1) (1 3 4=.)
encode C2_2_h, gen(C22h)
recode C22h  (2=-1) (5=1) (1 3 4=.)
encode C2_2_i, gen(C22i)
recode C22i  (2=-1) (5=1) (1 3 4=.)
encode C2_3_a, gen(C23)
recode C23  (2=-1) (5=1) (1 3 4=.)
encode C2_3_b, gen(C23b)
recode C23b  (2=-1) (5=1) (1 3 4=.)
encode C2_3_c, gen(C23c)
recode C23c  (2=-1) (5=1) (1 3 4=.)
encode C2_3_d, gen(C23d)
recode C23d  (2=-1) (5=1) (1 3 4=.)
encode C2_3_e, gen(C23e)
recode C23e  (2=-1) (5=1) (1 3 4=.)
encode C2_3_f, gen(C23f)
recode C23f  (2=-1) (5=1) (1 3 4=.)
encode C2_3_g, gen(C23g)
recode C23g  (2=-1) (5=1) (1 3 4=.)
encode C2_3_h, gen(C23h)
recode C23h  (2=-1) (5=1) (1 3 4=.)
encode C2_3_i, gen(C23i)
recode C23i  (2=-1) (5=1) (1 3 4=.)
encode C2_4_a, gen(C24)
recode C24  (2=-1) (5=1) (1 3 4=.)
encode C2_4_b, gen(C24b)
recode C24b  (2=-1) (5=1) (1 3 4=.)
encode C2_4_c, gen(C24c)
recode C24c  (2=-1) (5=1) (1 3 4=.)
encode C2_4_d, gen(C24d)
recode C24d  (2=-1) (5=1) (1 3 4=.)
encode C2_4_e, gen(C24e)
recode C24e  (2=-1) (5=1) (1 3 4=.)
encode C2_4_f, gen(C24f)
recode C24f  (2=-1) (5=1) (1 3 4=.)
encode C2_4_g, gen(C24g)
recode C24g  (2=-1) (5=1) (1 3 4=.)
encode C2_4_h, gen(C24h)
recode C24h  (2=-1) (5=1) (1 3 4=.)
encode C2_4_i, gen(C24i)
recode C24i  (2=-1) (5=1) (1 3 4=.)
 encode C3_1a , gen(C31)
 recode C31 (1=-1) (2 5 6 =.) (3=1) (4=0)
 encode C3_1b_1 , gen(C31b)
 recode C31b (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_1b_2 , gen(C31c)
 recode C31c (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_1b_3 , gen(C31d)
 recode C31d (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_1b_4 , gen(C31e)
 recode C31e (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_1b_5 , gen(C31f)
 recode C31f (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_1b_6 , gen(C31g)
 recode C31g (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_1b_7 , gen(C31h)
 recode C31h (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_1b_8 , gen(C31i)
 recode C31i (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_2a , gen(C32)
 recode C32 (1=-1) (2 5 6 =.) (3=1) (4=0)
 encode C3_2b_1 , gen(C32b)
 recode C32b (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_2b_2 , gen(C32c)
 recode C32c (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_2b_3 , gen(C32d)
 recode C32d (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_2b_4 , gen(C32e)
 recode C32e (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_2b_5 , gen(C32f)
 recode C32f (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_2b_6 , gen(C32g)
 recode C32g (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_2b_7 , gen(C32h)
 recode C32h (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_2b_8 , gen(C32i)
 recode C32i (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_3a , gen(C33)
 recode C33 (1=-1) (2 5 6 =.) (3=1) (4=0)
 encode C3_3b_1 , gen(C33b)
 recode C33b (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_3b_2 , gen(C33c)
 recode C33c (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_3b_3 , gen(C33d)
 recode C33d (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_3b_4 , gen(C33e)
 recode C33e (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_3b_5 , gen(C33f)
 recode C33f (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_3b_6 , gen(C33g)
 recode C33g (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_3b_7 , gen(C33h)
 recode C33h (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_3b_8 , gen(C33i)
 recode C33i (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_4a , gen(C34)
 recode C34 (1=-1) (2 5 6 =.) (3=1) (4=0)
 encode C3_4b_1 , gen(C34b)
 recode C34b (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_4b_2 , gen(C34c)
 recode C34c (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_4b_3 , gen(C34d)
 recode C34d (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_4b_4 , gen(C34e)
 recode C34e (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_4b_5 , gen(C34f)
 recode C34f (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_4b_6 , gen(C34g)
 recode C34g (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_4b_7 , gen(C34h)
 recode C34h (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C3_4b_8 , gen(C34i)
 recode C34i (1=-1) (2 5 6 7=.) (3=1) (4=0)
 encode C4_1a, gen(C41)
 recode C41 (2=-1) (4=0) (3 5 6=.)
 encode C4_1b_1, gen(C41b)
 recode C41b (2=-1) (4=0) (3 5 6 7=.)
 encode C4_1b_2, gen(C41c)
 recode C41c (2=-1) (4=0) (3 5 6 7=.)
 encode C4_1b_3, gen(C41d)
 recode C41d (2=-1) (4=0) (3 5 6 7=.)
 encode C4_1b_4, gen(C41e)
 recode C41e (2=-1) (4=0) (3 5 6 7=.)
 encode C4_1b_5, gen(C41f)
 recode C41f (2=-1) (4=0) (3 5 6 7=.)
 encode C4_1b_6, gen(C41g)
 recode C41g (2=-1) (4=0) (3 5 6 7=.)
 encode C4_1b_7, gen(C41h)
 recode C41h (2=-1) (4=0) (3 5 6 7=.)
 encode C4_1b_8, gen(C41i)
 recode C41i (2=-1) (4=0) (3 5 6 7=.)
 replace C11 = (C11-4)/3
 replace C11b = (C11b-4)/3
  replace C11c = (C11c-4)/3
   replace C11d = (C11d-4)/3
    replace C11e = (C11e-4)/3
	 replace C11f = (C11f-4)/3
	  replace C11g = (C11g-4)/3
	   replace C11h = (C11h-4)/3
	   replace C11i = (C11i-4)/3
 replace C13 = (C13-4)/3
 replace C13b = (C13b-4)/3
  replace C13c = (C13c-4)/3
   replace C13d = (C13d-4)/3
    replace C13e = (C13e-4)/3
	 replace C13f = (C13f-4)/3
	  replace C13g = (C13g-4)/3
	   replace C13h = (C13h-4)/3
	   replace C13i = (C13i-4)/3
 replace C14 = (C14-4)/3
 replace C14b = (C14b-4)/3
  replace C14c = (C14c-4)/3
   replace C14d = (C14d-4)/3
    replace C14e = (C14e-4)/3
	 replace C14f = (C14f-4)/3
	  replace C14g = (C14g-4)/3
	   replace C14h = (C14h-4)/3
	   replace C14i = (C14i-4)/3
	   
	   //reverse:  -1 left - +1 right 	   
	   recode C21 C23 C24 C31 C32 C33  (1=-1) (-1=1)
	   recode C21b C23b C24b C31b C32b C33b  (1=-1) (-1=1)
	   recode C21c C23c C24c C31c C32c C33c  (1=-1) (-1=1)
	   recode C21d C23d C24d C31d C32d C33d  (1=-1) (-1=1)
	   recode C21e C23e C24e C31e C32e C33e  (1=-1) (-1=1)
	   recode C21f C23f C24f C31f C32f C33f  (1=-1) (-1=1)	   
	   recode C21g C23g C24g C31g C32g C33g  (1=-1) (-1=1)
	   recode C21h C23h C24h C31h C32h C33h  (1=-1) (-1=1)
	   recode C21i C23i C24i C31i C32i C33i  (1=-1) (-1=1) 
	   
//gen PID
encode CLOSEPTY2, gen(party)
tab party, gen (party_)	   
recode party (42 43 44 45 23 2 =1)
	   
//stacking data
reshape long ptv , i(ca) j(partyn)
gen partytype=0

//generate average positions on issues
egen mC11 = wtmean(C11) , by(country) weight(wei)
egen mC11b = wtmean(C11b) , by(country) weight(wei)
egen mC11c = wtmean(C11c) , by(country) weight(wei)
egen mC11d = wtmean(C11d) , by(country) weight(wei)
egen mC11e = wtmean(C11e) , by(country) weight(wei)
egen mC11f = wtmean(C11f) , by(country) weight(wei)
egen mC11g = wtmean(C11g) , by(country) weight(wei)
egen mC11h = wtmean(C11h) , by(country) weight(wei)
egen mC11i = wtmean(C11i) , by(country) weight(wei)
egen mC13 = wtmean(C13) , by(country) weight(wei)
egen mC13b = wtmean(C13b) , by(country) weight(wei)
egen mC13c = wtmean(C13c) , by(country) weight(wei)
egen mC13d = wtmean(C13d) , by(country) weight(wei)
egen mC13e = wtmean(C13e) , by(country) weight(wei)
egen mC13f = wtmean(C13f) , by(country) weight(wei)
egen mC13g = wtmean(C13g) , by(country) weight(wei)
egen mC13h = wtmean(C13h) , by(country) weight(wei)
egen mC13i = wtmean(C13i) , by(country) weight(wei)
egen mC14 = wtmean(C14) , by(country) weight(wei)
egen mC14b = wtmean(C14b) , by(country) weight(wei)
egen mC14c = wtmean(C14c) , by(country) weight(wei)
egen mC14d = wtmean(C14d) , by(country) weight(wei)
egen mC14e = wtmean(C14e) , by(country) weight(wei)
egen mC14f = wtmean(C14f) , by(country) weight(wei)
egen mC14g = wtmean(C14g) , by(country) weight(wei)
egen mC14h = wtmean(C14h) , by(country) weight(wei)
egen mC14i = wtmean(C14i) , by(country) weight(wei)
egen mC21 = wtmean(C21) , by(country) weight(wei)
egen mC21b = wtmean(C21b) , by(country) weight(wei)
egen mC21c = wtmean(C21c) , by(country) weight(wei)
egen mC21d = wtmean(C21d) , by(country) weight(wei)
egen mC21e = wtmean(C21e) , by(country) weight(wei)
egen mC21f = wtmean(C21f) , by(country) weight(wei)
egen mC21g = wtmean(C21g) , by(country) weight(wei)
egen mC21h = wtmean(C21h) , by(country) weight(wei)
egen mC21i = wtmean(C21i) , by(country) weight(wei)
egen mC22 = wtmean(C22) , by(country) weight(wei)
egen mC22b = wtmean(C22b) , by(country) weight(wei)
egen mC22c = wtmean(C22c) , by(country) weight(wei)
egen mC22d = wtmean(C22d) , by(country) weight(wei)
egen mC22e = wtmean(C22e) , by(country) weight(wei)
egen mC22f = wtmean(C22f) , by(country) weight(wei)
egen mC22g = wtmean(C22g) , by(country) weight(wei)
egen mC22h = wtmean(C22h) , by(country) weight(wei)
egen mC22i = wtmean(C22i) , by(country) weight(wei)
egen mC23 = wtmean(C23) , by(country) weight(wei)
egen mC23b = wtmean(C23b) , by(country) weight(wei)
egen mC23c = wtmean(C23c) , by(country) weight(wei)
egen mC23d = wtmean(C23d) , by(country) weight(wei)
egen mC23e = wtmean(C23e) , by(country) weight(wei)
egen mC23f = wtmean(C23f) , by(country) weight(wei)
egen mC23g = wtmean(C23g) , by(country) weight(wei)
egen mC23h = wtmean(C23h) , by(country) weight(wei)
egen mC23i = wtmean(C23i) , by(country) weight(wei)
egen mC24 = wtmean(C24) , by(country) weight(wei)
egen mC24b = wtmean(C24b) , by(country) weight(wei)
egen mC24c = wtmean(C24c) , by(country) weight(wei)
egen mC24d = wtmean(C24d) , by(country) weight(wei)
egen mC24e = wtmean(C24e) , by(country) weight(wei)
egen mC24f = wtmean(C24f) , by(country) weight(wei)
egen mC24g = wtmean(C24g) , by(country) weight(wei)
egen mC24h = wtmean(C24h) , by(country) weight(wei)
egen mC24i = wtmean(C24i) , by(country) weight(wei)
egen mC31 = wtmean(C31) , by(country) weight(wei)
egen mC31b = wtmean(C31b) , by(country) weight(wei)
egen mC31c = wtmean(C31c) , by(country) weight(wei)
egen mC31d = wtmean(C31d) , by(country) weight(wei)
egen mC31e = wtmean(C31e) , by(country) weight(wei)
egen mC31f = wtmean(C31f) , by(country) weight(wei)
egen mC31g = wtmean(C31g) , by(country) weight(wei)
egen mC31h = wtmean(C31h) , by(country) weight(wei)
egen mC31i = wtmean(C31i) , by(country) weight(wei)
egen mC32 = wtmean(C32) , by(country) weight(wei)
egen mC32b = wtmean(C32b) , by(country) weight(wei)
egen mC32c = wtmean(C32c) , by(country) weight(wei)
egen mC32d = wtmean(C32d) , by(country) weight(wei)
egen mC32e = wtmean(C32e) , by(country) weight(wei)
egen mC32f = wtmean(C32f) , by(country) weight(wei)
egen mC32g = wtmean(C32g) , by(country) weight(wei)
egen mC32h = wtmean(C32h) , by(country) weight(wei)
egen mC32i = wtmean(C32i) , by(country) weight(wei)
egen mC33 = wtmean(C33) , by(country) weight(wei)
egen mC33b = wtmean(C33b) , by(country) weight(wei)
egen mC33c = wtmean(C33c) , by(country) weight(wei)
egen mC33d = wtmean(C33d) , by(country) weight(wei)
egen mC33e = wtmean(C33e) , by(country) weight(wei)
egen mC33f = wtmean(C33f) , by(country) weight(wei)
egen mC33g = wtmean(C33g) , by(country) weight(wei)
egen mC33h = wtmean(C33h) , by(country) weight(wei)
egen mC33i = wtmean(C33i) , by(country) weight(wei)
egen mC34 = wtmean(C34) , by(country) weight(wei)
egen mC34b = wtmean(C34b) , by(country) weight(wei)
egen mC34c = wtmean(C34c) , by(country) weight(wei)
egen mC34d = wtmean(C34d) , by(country) weight(wei)
egen mC34e = wtmean(C34e) , by(country) weight(wei)
egen mC34f = wtmean(C34f) , by(country) weight(wei)
egen mC34g = wtmean(C34g) , by(country) weight(wei)
egen mC34h = wtmean(C34h) , by(country) weight(wei)
egen mC34i = wtmean(C34i) , by(country) weight(wei)
egen mC41 = wtmean(C41) , by(country) weight(wei)
egen mC41b = wtmean(C41b) , by(country) weight(wei)
egen mC41c = wtmean(C41c) , by(country) weight(wei)
egen mC41d = wtmean(C41d) , by(country) weight(wei)
egen mC41e = wtmean(C41e) , by(country) weight(wei)
egen mC41f = wtmean(C41f) , by(country) weight(wei)
egen mC41g = wtmean(C41g) , by(country) weight(wei)
egen mC41h = wtmean(C41h) , by(country) weight(wei)
egen mC41i = wtmean(C41i) , by(country) weight(wei)

//for each R generate objective issue distances from all parties on all issues [from party average placement]
gen delta13 = .
/* US_dem:*/ replace delta13 = abs(C13 - mC13b)  if country=="US" & partyn==1 
/* US_rep:*/ replace delta13 = abs(C13 - mC13c)  if country=="US" & partyn==2
/* UK_lab:*/ replace delta13 = abs(C13 - mC13c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace delta13 = abs(C13 - mC13b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace delta13 = abs(C13 - mC13h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace delta13 = abs(C13 - mC13d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace delta13 = abs(C13 - mC13e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace delta13 = abs(C13 - mC13f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace delta13 = abs(C13 - mC13d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace delta13 = abs(C13 - mC13c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace delta13 = abs(C13 - mC13g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace delta13 = abs(C13 - mC13b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace delta13 = abs(C13 - mC13d) if country=="IT" & partyn==3
/* IT_fi:*/ replace delta13 = abs(C13 - mC13c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace delta13 = abs(C13 - mC13e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace delta13 = abs(C13 - mC13f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace delta13 = abs(C13 - mC13f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace delta13 = abs(C13 - mC13b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace delta13 = abs(C13 - mC13e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace delta13 = abs(C13 - mC13d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace delta13 = abs(C13 - mC13e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace delta13 = abs(C13 - mC13d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace delta13 = abs(C13 - mC13c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace delta13 = abs(C13 - mC13c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace delta13 = abs(C13 - mC13g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace delta13 = abs(C13 - mC13i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace delta13 = abs(C13 - mC13e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace delta13 = abs(C13 - mC13h)  if country=="DEN"  & partyn==7
gen delta31 = .
/* US_dem:*/ replace delta31 = abs(C31 - mC31b)  if country=="US" & partyn==1 
/* US_rep:*/ replace delta31 = abs(C31 - mC31c)  if country=="US" & partyn==2
/* UK_lab:*/ replace delta31 = abs(C31 - mC31c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace delta31 = abs(C31 - mC31b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace delta31 = abs(C31 - mC31h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace delta31 = abs(C31 - mC31d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace delta31 = abs(C31 - mC31e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace delta31 = abs(C31 - mC31f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace delta31 = abs(C31 - mC31d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace delta31 = abs(C31 - mC31c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace delta31 = abs(C31 - mC31g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace delta31 = abs(C31 - mC31b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace delta31 = abs(C31 - mC31d) if country=="IT" & partyn==3
/* IT_fi:*/ replace delta31 = abs(C31 - mC31c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace delta31 = abs(C31 - mC31e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace delta31 = abs(C31 - mC31f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace delta31 = abs(C31 - mC31f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace delta31 = abs(C31 - mC31b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace delta31 = abs(C31 - mC31e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace delta31 = abs(C31 - mC31d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace delta31 = abs(C31 - mC31e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace delta31 = abs(C31 - mC31d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace delta31 = abs(C31 - mC31c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace delta31 = abs(C31 - mC31c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace delta31 = abs(C31 - mC31g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace delta31 = abs(C31 - mC31i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace delta31 = abs(C31 - mC31e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace delta31 = abs(C31 - mC31h)  if country=="DEN"  & partyn==7
gen delta14 = .
/* US_dem:*/ replace delta14 = abs(C14 - mC14b)  if country=="US" & partyn==1 
/* US_rep:*/ replace delta14 = abs(C14 - mC14c)  if country=="US" & partyn==2
/* UK_lab:*/ replace delta14 = abs(C14 - mC14c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace delta14 = abs(C14 - mC14b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace delta14 = abs(C14 - mC14h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace delta14 = abs(C14 - mC14d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace delta14 = abs(C14 - mC14e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace delta14 = abs(C14 - mC14f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace delta14 = abs(C14 - mC14d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace delta14 = abs(C14 - mC14c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace delta14 = abs(C14 - mC14g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace delta14 = abs(C14 - mC14b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace delta14 = abs(C14 - mC14d) if country=="IT" & partyn==3
/* IT_fi:*/ replace delta14 = abs(C14 - mC14c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace delta14 = abs(C14 - mC14e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace delta14 = abs(C14 - mC14f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace delta14 = abs(C14 - mC14f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace delta14 = abs(C14 - mC14b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace delta14 = abs(C14 - mC14e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace delta14 = abs(C14 - mC14d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace delta14 = abs(C14 - mC14e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace delta14 = abs(C14 - mC14d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace delta14 = abs(C14 - mC14c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace delta14 = abs(C14 - mC14c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace delta14 = abs(C14 - mC14g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace delta14 = abs(C14 - mC14i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace delta14 = abs(C14 - mC14e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace delta14 = abs(C14 - mC14h)  if country=="DEN"  & partyn==7
gen delta21 = .
/* US_dem:*/ replace delta21 = abs(C21 - mC21b)  if country=="US" & partyn==1 
/* US_rep:*/ replace delta21 = abs(C21 - mC21c)  if country=="US" & partyn==2
/* UK_lab:*/ replace delta21 = abs(C21 - mC21c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace delta21 = abs(C21 - mC21b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace delta21 = abs(C21 - mC21h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace delta21 = abs(C21 - mC21d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace delta21 = abs(C21 - mC21e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace delta21 = abs(C21 - mC21f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace delta21 = abs(C21 - mC21d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace delta21 = abs(C21 - mC21c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace delta21 = abs(C21 - mC21g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace delta21 = abs(C21 - mC21b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace delta21 = abs(C21 - mC21d) if country=="IT" & partyn==3
/* IT_fi:*/ replace delta21 = abs(C21 - mC21c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace delta21 = abs(C21 - mC21e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace delta21 = abs(C21 - mC21f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace delta21 = abs(C21 - mC21f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace delta21 = abs(C21 - mC21b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace delta21 = abs(C21 - mC21e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace delta21 = abs(C21 - mC21d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace delta21 = abs(C21 - mC21e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace delta21 = abs(C21 - mC21d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace delta21 = abs(C21 - mC21c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace delta21 = abs(C21 - mC21c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace delta21 = abs(C21 - mC21g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace delta21 = abs(C21 - mC21i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace delta21 = abs(C21 - mC21e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace delta21 = abs(C21 - mC21h)  if country=="DEN"  & partyn==7
gen delta22 = .
/* US_dem:*/ replace delta22 = abs(C22 - mC22b)  if country=="US" & partyn==1 
/* US_rep:*/ replace delta22 = abs(C22 - mC22c)  if country=="US" & partyn==2
/* UK_lab:*/ replace delta22 = abs(C22 - mC22c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace delta22 = abs(C22 - mC22b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace delta22 = abs(C22 - mC22h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace delta22 = abs(C22 - mC22d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace delta22 = abs(C22 - mC22e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace delta22 = abs(C22 - mC22f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace delta22 = abs(C22 - mC22d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace delta22 = abs(C22 - mC22c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace delta22 = abs(C22 - mC22g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace delta22 = abs(C22 - mC22b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace delta22 = abs(C22 - mC22d) if country=="IT" & partyn==3
/* IT_fi:*/ replace delta22 = abs(C22 - mC22c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace delta22 = abs(C22 - mC22e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace delta22 = abs(C22 - mC22f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace delta22 = abs(C22 - mC22f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace delta22 = abs(C22 - mC22b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace delta22 = abs(C22 - mC22e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace delta22 = abs(C22 - mC22d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace delta22 = abs(C22 - mC22e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace delta22 = abs(C22 - mC22d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace delta22 = abs(C22 - mC22c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace delta22 = abs(C22 - mC22c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace delta22 = abs(C22 - mC22g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace delta22 = abs(C22 - mC22i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace delta22 = abs(C22 - mC22e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace delta22 = abs(C22 - mC22h)  if country=="DEN"  & partyn==7
gen delta23 = .
/* US_dem:*/ replace delta23 = abs(C23 - mC23b)  if country=="US" & partyn==1 
/* US_rep:*/ replace delta23 = abs(C23 - mC23c)  if country=="US" & partyn==2
/* UK_lab:*/ replace delta23 = abs(C23 - mC23c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace delta23 = abs(C23 - mC23b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace delta23 = abs(C23 - mC23h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace delta23 = abs(C23 - mC23d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace delta23 = abs(C23 - mC23e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace delta23 = abs(C23 - mC23f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace delta23 = abs(C23 - mC23d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace delta23 = abs(C23 - mC23c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace delta23 = abs(C23 - mC23g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace delta23 = abs(C23 - mC23b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace delta23 = abs(C23 - mC23d) if country=="IT" & partyn==3
/* IT_fi:*/ replace delta23 = abs(C23 - mC23c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace delta23 = abs(C23 - mC23e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace delta23 = abs(C23 - mC23f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace delta23 = abs(C23 - mC23f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace delta23 = abs(C23 - mC23b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace delta23 = abs(C23 - mC23e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace delta23 = abs(C23 - mC23d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace delta23 = abs(C23 - mC23e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace delta23 = abs(C23 - mC23d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace delta23 = abs(C23 - mC23c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace delta23 = abs(C23 - mC23c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace delta23 = abs(C23 - mC23g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace delta23 = abs(C23 - mC23i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace delta23 = abs(C23 - mC23e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace delta23 = abs(C23 - mC23h)  if country=="DEN"  & partyn==7
gen delta24 = .
/* US_dem:*/ replace delta24 = abs(C24 - mC24b)  if country=="US" & partyn==1 
/* US_rep:*/ replace delta24 = abs(C24 - mC24c)  if country=="US" & partyn==2
/* UK_lab:*/ replace delta24 = abs(C24 - mC24c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace delta24 = abs(C24 - mC24b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace delta24 = abs(C24 - mC24h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace delta24 = abs(C24 - mC24d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace delta24 = abs(C24 - mC24e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace delta24 = abs(C24 - mC24f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace delta24 = abs(C24 - mC24d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace delta24 = abs(C24 - mC24c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace delta24 = abs(C24 - mC24g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace delta24 = abs(C24 - mC24b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace delta24 = abs(C24 - mC24d) if country=="IT" & partyn==3
/* IT_fi:*/ replace delta24 = abs(C24 - mC24c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace delta24 = abs(C24 - mC24e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace delta24 = abs(C24 - mC24f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace delta24 = abs(C24 - mC24f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace delta24 = abs(C24 - mC24b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace delta24 = abs(C24 - mC24e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace delta24 = abs(C24 - mC24d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace delta24 = abs(C24 - mC24e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace delta24 = abs(C24 - mC24d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace delta24 = abs(C24 - mC24c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace delta24 = abs(C24 - mC24c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace delta24 = abs(C24 - mC24g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace delta24 = abs(C24 - mC24i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace delta24 = abs(C24 - mC24e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace delta24 = abs(C24 - mC24h)  if country=="DEN"  & partyn==7
gen delta32 = .
/* US_dem:*/ replace delta32 = abs(C32 - mC32b)  if country=="US" & partyn==1 
/* US_rep:*/ replace delta32 = abs(C32 - mC32c)  if country=="US" & partyn==2
/* UK_lab:*/ replace delta32 = abs(C32 - mC32c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace delta32 = abs(C32 - mC32b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace delta32 = abs(C32 - mC32h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace delta32 = abs(C32 - mC32d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace delta32 = abs(C32 - mC32e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace delta32 = abs(C32 - mC32f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace delta32 = abs(C32 - mC32d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace delta32 = abs(C32 - mC32c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace delta32 = abs(C32 - mC32g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace delta32 = abs(C32 - mC32b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace delta32 = abs(C32 - mC32d) if country=="IT" & partyn==3
/* IT_fi:*/ replace delta32 = abs(C32 - mC32c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace delta32 = abs(C32 - mC32e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace delta32 = abs(C32 - mC32f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace delta32 = abs(C32 - mC32f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace delta32 = abs(C32 - mC32b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace delta32 = abs(C32 - mC32e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace delta32 = abs(C32 - mC32d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace delta32 = abs(C32 - mC32e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace delta32 = abs(C32 - mC32d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace delta32 = abs(C32 - mC32c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace delta32 = abs(C32 - mC32c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace delta32 = abs(C32 - mC32g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace delta32 = abs(C32 - mC32i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace delta32 = abs(C32 - mC32e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace delta32 = abs(C32 - mC32h)  if country=="DEN"  & partyn==7
gen delta33 = .
/* US_dem:*/ replace delta33 = abs(C33 - mC33b)  if country=="US" & partyn==1 
/* US_rep:*/ replace delta33 = abs(C33 - mC33c)  if country=="US" & partyn==2
/* UK_lab:*/ replace delta33 = abs(C33 - mC33c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace delta33 = abs(C33 - mC33b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace delta33 = abs(C33 - mC33h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace delta33 = abs(C33 - mC33d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace delta33 = abs(C33 - mC33e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace delta33 = abs(C33 - mC33f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace delta33 = abs(C33 - mC33d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace delta33 = abs(C33 - mC33c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace delta33 = abs(C33 - mC33g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace delta33 = abs(C33 - mC33b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace delta33 = abs(C33 - mC33d) if country=="IT" & partyn==3
/* IT_fi:*/ replace delta33 = abs(C33 - mC33c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace delta33 = abs(C33 - mC33e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace delta33 = abs(C33 - mC33f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace delta33 = abs(C33 - mC33f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace delta33 = abs(C33 - mC33b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace delta33 = abs(C33 - mC33e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace delta33 = abs(C33 - mC33d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace delta33 = abs(C33 - mC33e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace delta33 = abs(C33 - mC33d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace delta33 = abs(C33 - mC33c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace delta33 = abs(C33 - mC33c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace delta33 = abs(C33 - mC33g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace delta33 = abs(C33 - mC33i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace delta33 = abs(C33 - mC33e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace delta33 = abs(C33 - mC33h)  if country=="DEN"  & partyn==7
gen delta34 = .
/* US_dem:*/ replace delta34 = abs(C34 - mC34b)  if country=="US" & partyn==1 
/* US_rep:*/ replace delta34 = abs(C34 - mC34c)  if country=="US" & partyn==2
/* UK_lab:*/ replace delta34 = abs(C34 - mC34c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace delta34 = abs(C34 - mC34b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace delta34 = abs(C34 - mC34h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace delta34 = abs(C34 - mC34d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace delta34 = abs(C34 - mC34e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace delta34 = abs(C34 - mC34f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace delta34 = abs(C34 - mC34d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace delta34 = abs(C34 - mC34c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace delta34 = abs(C34 - mC34g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace delta34 = abs(C34 - mC34b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace delta34 = abs(C34 - mC34d) if country=="IT" & partyn==3
/* IT_fi:*/ replace delta34 = abs(C34 - mC34c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace delta34 = abs(C34 - mC34e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace delta34 = abs(C34 - mC34f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace delta34 = abs(C34 - mC34f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace delta34 = abs(C34 - mC34b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace delta34 = abs(C34 - mC34e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace delta34 = abs(C34 - mC34d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace delta34 = abs(C34 - mC34e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace delta34 = abs(C34 - mC34d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace delta34 = abs(C34 - mC34c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace delta34 = abs(C34 - mC34c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace delta34 = abs(C34 - mC34g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace delta34 = abs(C34 - mC34i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace delta34 = abs(C34 - mC34e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace delta34 = abs(C34 - mC34h)  if country=="DEN"  & partyn==7
gen delta41 = .
/* US_dem:*/ replace delta41 = abs(C41 - mC41b)  if country=="US" & partyn==1 
/* US_rep:*/ replace delta41 = abs(C41 - mC41c)  if country=="US" & partyn==2
/* UK_lab:*/ replace delta41 = abs(C41 - mC41c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace delta41 = abs(C41 - mC41b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace delta41 = abs(C41 - mC41h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace delta41 = abs(C41 - mC41d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace delta41 = abs(C41 - mC41e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace delta41 = abs(C41 - mC41f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace delta41 = abs(C41 - mC41d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace delta41 = abs(C41 - mC41c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace delta41 = abs(C41 - mC41g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace delta41 = abs(C41 - mC41b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace delta41 = abs(C41 - mC41d) if country=="IT" & partyn==3
/* IT_fi:*/ replace delta41 = abs(C41 - mC41c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace delta41 = abs(C41 - mC41e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace delta41 = abs(C41 - mC41f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace delta41 = abs(C41 - mC41f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace delta41 = abs(C41 - mC41b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace delta41 = abs(C41 - mC41e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace delta41 = abs(C41 - mC41d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace delta41 = abs(C41 - mC41e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace delta41 = abs(C41 - mC41d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace delta41 = abs(C41 - mC41c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace delta41 = abs(C41 - mC41c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace delta41 = abs(C41 - mC41g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace delta41 = abs(C41 - mC41i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace delta41 = abs(C41 - mC41e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace delta41 = abs(C41 - mC41h)  if country=="DEN"  & partyn==7
gen delta11 = .
/* US_dem:*/ replace delta11 = abs(C11 - mC11b)  if country=="US" & partyn==1 
/* US_rep:*/ replace delta11 = abs(C11 - mC11c)  if country=="US" & partyn==2
/* UK_lab:*/ replace delta11 = abs(C11 - mC11c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace delta11 = abs(C11 - mC11b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace delta11 = abs(C11 - mC11h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace delta11 = abs(C11 - mC11d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace delta11 = abs(C11 - mC11e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace delta11 = abs(C11 - mC11f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace delta11 = abs(C11 - mC11d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace delta11 = abs(C11 - mC11c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace delta11 = abs(C11 - mC11g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace delta11 = abs(C11 - mC11b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace delta11 = abs(C11 - mC11d) if country=="IT" & partyn==3
/* IT_fi:*/ replace delta11 = abs(C11 - mC11c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace delta11 = abs(C11 - mC11e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace delta11 = abs(C11 - mC11f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace delta11 = abs(C11 - mC11f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace delta11 = abs(C11 - mC11b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace delta11 = abs(C11 - mC11e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace delta11 = abs(C11 - mC11d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace delta11 = abs(C11 - mC11e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace delta11 = abs(C11 - mC11d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace delta11 = abs(C11 - mC11c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace delta11 = abs(C11 - mC11c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace delta11 = abs(C11 - mC11g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace delta11 = abs(C11 - mC11i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace delta11 = abs(C11 - mC11e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace delta11 = abs(C11 - mC11h)  if country=="DEN"  & partyn==7

//for each R generate subjective issue distances from all parties on all issues [from party placement in R's opinion]
gen s_delta13 = .
/* US_dem:*/ replace s_delta13 = abs(C13 - C13b)  if country=="US" & partyn==1 
/* US_rep:*/ replace s_delta13 = abs(C13 - C13c)  if country=="US" & partyn==2
/* UK_lab:*/ replace s_delta13 = abs(C13 - C13c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace s_delta13 = abs(C13 - C13b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace s_delta13 = abs(C13 - C13h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace s_delta13 = abs(C13 - C13d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace s_delta13 = abs(C13 - C13e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace s_delta13 = abs(C13 - C13f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace s_delta13 = abs(C13 - C13d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace s_delta13 = abs(C13 - C13c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace s_delta13 = abs(C13 - C13g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace s_delta13 = abs(C13 - C13b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace s_delta13 = abs(C13 - C13d) if country=="IT" & partyn==3
/* IT_fi:*/ replace s_delta13 = abs(C13 - C13c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace s_delta13 = abs(C13 - C13e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace s_delta13 = abs(C13 - C13f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace s_delta13 = abs(C13 - C13f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace s_delta13 = abs(C13 - C13b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace s_delta13 = abs(C13 - C13e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace s_delta13 = abs(C13 - C13d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace s_delta13 = abs(C13 - C13e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace s_delta13 = abs(C13 - C13d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace s_delta13 = abs(C13 - C13c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace s_delta13 = abs(C13 - C13c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace s_delta13 = abs(C13 - C13g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace s_delta13 = abs(C13 - C13i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace s_delta13 = abs(C13 - C13e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace s_delta13 = abs(C13 - C13h)  if country=="DEN"  & partyn==7
gen s_delta31 = .
/* US_dem:*/ replace s_delta31 = abs(C31 - C31b)  if country=="US" & partyn==1 
/* US_rep:*/ replace s_delta31 = abs(C31 - C31c)  if country=="US" & partyn==2
/* UK_lab:*/ replace s_delta31 = abs(C31 - C31c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace s_delta31 = abs(C31 - C31b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace s_delta31 = abs(C31 - C31h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace s_delta31 = abs(C31 - C31d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace s_delta31 = abs(C31 - C31e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace s_delta31 = abs(C31 - C31f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace s_delta31 = abs(C31 - C31d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace s_delta31 = abs(C31 - C31c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace s_delta31 = abs(C31 - C31g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace s_delta31 = abs(C31 - C31b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace s_delta31 = abs(C31 - C31d) if country=="IT" & partyn==3
/* IT_fi:*/ replace s_delta31 = abs(C31 - C31c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace s_delta31 = abs(C31 - C31e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace s_delta31 = abs(C31 - C31f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace s_delta31 = abs(C31 - C31f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace s_delta31 = abs(C31 - C31b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace s_delta31 = abs(C31 - C31e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace s_delta31 = abs(C31 - C31d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace s_delta31 = abs(C31 - C31e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace s_delta31 = abs(C31 - C31d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace s_delta31 = abs(C31 - C31c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace s_delta31 = abs(C31 - C31c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace s_delta31 = abs(C31 - C31g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace s_delta31 = abs(C31 - C31i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace s_delta31 = abs(C31 - C31e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace s_delta31 = abs(C31 - C31h)  if country=="DEN"  & partyn==7
gen s_delta14 = .
/* US_dem:*/ replace s_delta14 = abs(C14 - C14b)  if country=="US" & partyn==1 
/* US_rep:*/ replace s_delta14 = abs(C14 - C14c)  if country=="US" & partyn==2
/* UK_lab:*/ replace s_delta14 = abs(C14 - C14c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace s_delta14 = abs(C14 - C14b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace s_delta14 = abs(C14 - C14h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace s_delta14 = abs(C14 - C14d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace s_delta14 = abs(C14 - C14e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace s_delta14 = abs(C14 - C14f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace s_delta14 = abs(C14 - C14d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace s_delta14 = abs(C14 - C14c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace s_delta14 = abs(C14 - C14g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace s_delta14 = abs(C14 - C14b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace s_delta14 = abs(C14 - C14d) if country=="IT" & partyn==3
/* IT_fi:*/ replace s_delta14 = abs(C14 - C14c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace s_delta14 = abs(C14 - C14e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace s_delta14 = abs(C14 - C14f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace s_delta14 = abs(C14 - C14f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace s_delta14 = abs(C14 - C14b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace s_delta14 = abs(C14 - C14e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace s_delta14 = abs(C14 - C14d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace s_delta14 = abs(C14 - C14e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace s_delta14 = abs(C14 - C14d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace s_delta14 = abs(C14 - C14c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace s_delta14 = abs(C14 - C14c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace s_delta14 = abs(C14 - C14g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace s_delta14 = abs(C14 - C14i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace s_delta14 = abs(C14 - C14e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace s_delta14 = abs(C14 - C14h)  if country=="DEN"  & partyn==7
gen s_delta21 = .
/* US_dem:*/ replace s_delta21 = abs(C21 - C21b)  if country=="US" & partyn==1 
/* US_rep:*/ replace s_delta21 = abs(C21 - C21c)  if country=="US" & partyn==2
/* UK_lab:*/ replace s_delta21 = abs(C21 - C21c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace s_delta21 = abs(C21 - C21b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace s_delta21 = abs(C21 - C21h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace s_delta21 = abs(C21 - C21d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace s_delta21 = abs(C21 - C21e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace s_delta21 = abs(C21 - C21f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace s_delta21 = abs(C21 - C21d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace s_delta21 = abs(C21 - C21c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace s_delta21 = abs(C21 - C21g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace s_delta21 = abs(C21 - C21b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace s_delta21 = abs(C21 - C21d) if country=="IT" & partyn==3
/* IT_fi:*/ replace s_delta21 = abs(C21 - C21c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace s_delta21 = abs(C21 - C21e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace s_delta21 = abs(C21 - C21f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace s_delta21 = abs(C21 - C21f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace s_delta21 = abs(C21 - C21b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace s_delta21 = abs(C21 - C21e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace s_delta21 = abs(C21 - C21d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace s_delta21 = abs(C21 - C21e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace s_delta21 = abs(C21 - C21d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace s_delta21 = abs(C21 - C21c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace s_delta21 = abs(C21 - C21c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace s_delta21 = abs(C21 - C21g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace s_delta21 = abs(C21 - C21i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace s_delta21 = abs(C21 - C21e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace s_delta21 = abs(C21 - C21h)  if country=="DEN"  & partyn==7
gen s_delta22 = .
/* US_dem:*/ replace s_delta22 = abs(C22 - C22b)  if country=="US" & partyn==1 
/* US_rep:*/ replace s_delta22 = abs(C22 - C22c)  if country=="US" & partyn==2
/* UK_lab:*/ replace s_delta22 = abs(C22 - C22c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace s_delta22 = abs(C22 - C22b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace s_delta22 = abs(C22 - C22h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace s_delta22 = abs(C22 - C22d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace s_delta22 = abs(C22 - C22e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace s_delta22 = abs(C22 - C22f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace s_delta22 = abs(C22 - C22d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace s_delta22 = abs(C22 - C22c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace s_delta22 = abs(C22 - C22g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace s_delta22 = abs(C22 - C22b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace s_delta22 = abs(C22 - C22d) if country=="IT" & partyn==3
/* IT_fi:*/ replace s_delta22 = abs(C22 - C22c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace s_delta22 = abs(C22 - C22e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace s_delta22 = abs(C22 - C22f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace s_delta22 = abs(C22 - C22f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace s_delta22 = abs(C22 - C22b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace s_delta22 = abs(C22 - C22e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace s_delta22 = abs(C22 - C22d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace s_delta22 = abs(C22 - C22e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace s_delta22 = abs(C22 - C22d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace s_delta22 = abs(C22 - C22c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace s_delta22 = abs(C22 - C22c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace s_delta22 = abs(C22 - C22g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace s_delta22 = abs(C22 - C22i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace s_delta22 = abs(C22 - C22e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace s_delta22 = abs(C22 - C22h)  if country=="DEN"  & partyn==7
gen s_delta23 = .
/* US_dem:*/ replace s_delta23 = abs(C23 - C23b)  if country=="US" & partyn==1 
/* US_rep:*/ replace s_delta23 = abs(C23 - C23c)  if country=="US" & partyn==2
/* UK_lab:*/ replace s_delta23 = abs(C23 - C23c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace s_delta23 = abs(C23 - C23b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace s_delta23 = abs(C23 - C23h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace s_delta23 = abs(C23 - C23d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace s_delta23 = abs(C23 - C23e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace s_delta23 = abs(C23 - C23f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace s_delta23 = abs(C23 - C23d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace s_delta23 = abs(C23 - C23c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace s_delta23 = abs(C23 - C23g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace s_delta23 = abs(C23 - C23b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace s_delta23 = abs(C23 - C23d) if country=="IT" & partyn==3
/* IT_fi:*/ replace s_delta23 = abs(C23 - C23c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace s_delta23 = abs(C23 - C23e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace s_delta23 = abs(C23 - C23f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace s_delta23 = abs(C23 - C23f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace s_delta23 = abs(C23 - C23b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace s_delta23 = abs(C23 - C23e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace s_delta23 = abs(C23 - C23d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace s_delta23 = abs(C23 - C23e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace s_delta23 = abs(C23 - C23d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace s_delta23 = abs(C23 - C23c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace s_delta23 = abs(C23 - C23c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace s_delta23 = abs(C23 - C23g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace s_delta23 = abs(C23 - C23i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace s_delta23 = abs(C23 - C23e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace s_delta23 = abs(C23 - C23h)  if country=="DEN"  & partyn==7
gen s_delta24 = .
/* US_dem:*/ replace s_delta24 = abs(C24 - C24b)  if country=="US" & partyn==1 
/* US_rep:*/ replace s_delta24 = abs(C24 - C24c)  if country=="US" & partyn==2
/* UK_lab:*/ replace s_delta24 = abs(C24 - C24c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace s_delta24 = abs(C24 - C24b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace s_delta24 = abs(C24 - C24h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace s_delta24 = abs(C24 - C24d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace s_delta24 = abs(C24 - C24e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace s_delta24 = abs(C24 - C24f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace s_delta24 = abs(C24 - C24d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace s_delta24 = abs(C24 - C24c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace s_delta24 = abs(C24 - C24g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace s_delta24 = abs(C24 - C24b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace s_delta24 = abs(C24 - C24d) if country=="IT" & partyn==3
/* IT_fi:*/ replace s_delta24 = abs(C24 - C24c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace s_delta24 = abs(C24 - C24e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace s_delta24 = abs(C24 - C24f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace s_delta24 = abs(C24 - C24f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace s_delta24 = abs(C24 - C24b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace s_delta24 = abs(C24 - C24e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace s_delta24 = abs(C24 - C24d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace s_delta24 = abs(C24 - C24e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace s_delta24 = abs(C24 - C24d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace s_delta24 = abs(C24 - C24c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace s_delta24 = abs(C24 - C24c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace s_delta24 = abs(C24 - C24g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace s_delta24 = abs(C24 - C24i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace s_delta24 = abs(C24 - C24e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace s_delta24 = abs(C24 - C24h)  if country=="DEN"  & partyn==7
gen s_delta32 = .
/* US_dem:*/ replace s_delta32 = abs(C32 - C32b)  if country=="US" & partyn==1 
/* US_rep:*/ replace s_delta32 = abs(C32 - C32c)  if country=="US" & partyn==2
/* UK_lab:*/ replace s_delta32 = abs(C32 - C32c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace s_delta32 = abs(C32 - C32b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace s_delta32 = abs(C32 - C32h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace s_delta32 = abs(C32 - C32d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace s_delta32 = abs(C32 - C32e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace s_delta32 = abs(C32 - C32f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace s_delta32 = abs(C32 - C32d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace s_delta32 = abs(C32 - C32c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace s_delta32 = abs(C32 - C32g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace s_delta32 = abs(C32 - C32b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace s_delta32 = abs(C32 - C32d) if country=="IT" & partyn==3
/* IT_fi:*/ replace s_delta32 = abs(C32 - C32c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace s_delta32 = abs(C32 - C32e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace s_delta32 = abs(C32 - C32f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace s_delta32 = abs(C32 - C32f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace s_delta32 = abs(C32 - C32b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace s_delta32 = abs(C32 - C32e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace s_delta32 = abs(C32 - C32d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace s_delta32 = abs(C32 - C32e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace s_delta32 = abs(C32 - C32d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace s_delta32 = abs(C32 - C32c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace s_delta32 = abs(C32 - C32c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace s_delta32 = abs(C32 - C32g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace s_delta32 = abs(C32 - C32i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace s_delta32 = abs(C32 - C32e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace s_delta32 = abs(C32 - C32h)  if country=="DEN"  & partyn==7
gen s_delta33 = .
/* US_dem:*/ replace s_delta33 = abs(C33 - C33b)  if country=="US" & partyn==1 
/* US_rep:*/ replace s_delta33 = abs(C33 - C33c)  if country=="US" & partyn==2
/* UK_lab:*/ replace s_delta33 = abs(C33 - C33c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace s_delta33 = abs(C33 - C33b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace s_delta33 = abs(C33 - C33h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace s_delta33 = abs(C33 - C33d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace s_delta33 = abs(C33 - C33e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace s_delta33 = abs(C33 - C33f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace s_delta33 = abs(C33 - C33d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace s_delta33 = abs(C33 - C33c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace s_delta33 = abs(C33 - C33g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace s_delta33 = abs(C33 - C33b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace s_delta33 = abs(C33 - C33d) if country=="IT" & partyn==3
/* IT_fi:*/ replace s_delta33 = abs(C33 - C33c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace s_delta33 = abs(C33 - C33e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace s_delta33 = abs(C33 - C33f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace s_delta33 = abs(C33 - C33f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace s_delta33 = abs(C33 - C33b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace s_delta33 = abs(C33 - C33e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace s_delta33 = abs(C33 - C33d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace s_delta33 = abs(C33 - C33e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace s_delta33 = abs(C33 - C33d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace s_delta33 = abs(C33 - C33c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace s_delta33 = abs(C33 - C33c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace s_delta33 = abs(C33 - C33g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace s_delta33 = abs(C33 - C33i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace s_delta33 = abs(C33 - C33e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace s_delta33 = abs(C33 - C33h)  if country=="DEN"  & partyn==7
gen s_delta34 = .
/* US_dem:*/ replace s_delta34 = abs(C34 - C34b)  if country=="US" & partyn==1 
/* US_rep:*/ replace s_delta34 = abs(C34 - C34c)  if country=="US" & partyn==2
/* UK_lab:*/ replace s_delta34 = abs(C34 - C34c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace s_delta34 = abs(C34 - C34b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace s_delta34 = abs(C34 - C34h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace s_delta34 = abs(C34 - C34d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace s_delta34 = abs(C34 - C34e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace s_delta34 = abs(C34 - C34f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace s_delta34 = abs(C34 - C34d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace s_delta34 = abs(C34 - C34c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace s_delta34 = abs(C34 - C34g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace s_delta34 = abs(C34 - C34b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace s_delta34 = abs(C34 - C34d) if country=="IT" & partyn==3
/* IT_fi:*/ replace s_delta34 = abs(C34 - C34c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace s_delta34 = abs(C34 - C34e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace s_delta34 = abs(C34 - C34f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace s_delta34 = abs(C34 - C34f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace s_delta34 = abs(C34 - C34b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace s_delta34 = abs(C34 - C34e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace s_delta34 = abs(C34 - C34d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace s_delta34 = abs(C34 - C34e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace s_delta34 = abs(C34 - C34d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace s_delta34 = abs(C34 - C34c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace s_delta34 = abs(C34 - C34c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace s_delta34 = abs(C34 - C34g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace s_delta34 = abs(C34 - C34i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace s_delta34 = abs(C34 - C34e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace s_delta34 = abs(C34 - C34h)  if country=="DEN"  & partyn==7
gen s_delta41 = .
/* US_dem:*/ replace s_delta41 = abs(C41 - C41b)  if country=="US" & partyn==1 
/* US_rep:*/ replace s_delta41 = abs(C41 - C41c)  if country=="US" & partyn==2
/* UK_lab:*/ replace s_delta41 = abs(C41 - C41c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace s_delta41 = abs(C41 - C41b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace s_delta41 = abs(C41 - C41h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace s_delta41 = abs(C41 - C41d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace s_delta41 = abs(C41 - C41e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace s_delta41 = abs(C41 - C41f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace s_delta41 = abs(C41 - C41d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace s_delta41 = abs(C41 - C41c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace s_delta41 = abs(C41 - C41g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace s_delta41 = abs(C41 - C41b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace s_delta41 = abs(C41 - C41d) if country=="IT" & partyn==3
/* IT_fi:*/ replace s_delta41 = abs(C41 - C41c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace s_delta41 = abs(C41 - C41e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace s_delta41 = abs(C41 - C41f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace s_delta41 = abs(C41 - C41f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace s_delta41 = abs(C41 - C41b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace s_delta41 = abs(C41 - C41e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace s_delta41 = abs(C41 - C41d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace s_delta41 = abs(C41 - C41e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace s_delta41 = abs(C41 - C41d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace s_delta41 = abs(C41 - C41c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace s_delta41 = abs(C41 - C41c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace s_delta41 = abs(C41 - C41g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace s_delta41 = abs(C41 - C41i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace s_delta41 = abs(C41 - C41e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace s_delta41 = abs(C41 - C41h)  if country=="DEN"  & partyn==7
gen s_delta11 = .
/* US_dem:*/ replace s_delta11 = abs(C11 - C11b)  if country=="US" & partyn==1 
/* US_rep:*/ replace s_delta11 = abs(C11 - C11c)  if country=="US" & partyn==2
/* UK_lab:*/ replace s_delta11 = abs(C11 - C11c)  if country=="UK" & partyn==2 
/* UK_con:*/ replace s_delta11 = abs(C11 - C11b)  if country=="UK"  & partyn==1 
/* UK_ukip:*/ replace s_delta11 = abs(C11 - C11h)  if country=="UK" & partyn==7
/* UK_gre:*/ replace s_delta11 = abs(C11 - C11d)  if country=="UK" & partyn==3
/* FR_ps:*/ replace s_delta11 = abs(C11 - C11e) if country=="FR"  & partyn==4
/* FR_ump:*/ replace s_delta11 = abs(C11 - C11f)  if country=="FR" & partyn==5
/* FR_fn:*/ replace s_delta11 = abs(C11 - C11d)  if country=="FR"  & partyn==3
/* FR_gau:*/ replace s_delta11 = abs(C11 - C11c)  if country=="FR"  & partyn==2
/* FR_gre:*/ replace s_delta11 = abs(C11 - C11g)  if country=="FR"  & partyn==6
/* IT_pd:*/ replace s_delta11 = abs(C11 - C11b)  if country=="IT"  & partyn==1 
/* IT_m5s:*/ replace s_delta11 = abs(C11 - C11d) if country=="IT" & partyn==3
/* IT_fi:*/ replace s_delta11 = abs(C11 - C11c)  if country=="IT" & partyn==2
/* IT_ln:*/ replace s_delta11 = abs(C11 - C11e)  if country=="IT"  & partyn==4 
/* IT_sel:*/ replace s_delta11 = abs(C11 - C11f) if country=="IT"  & partyn==5
/* GE_spd:*/ replace s_delta11 = abs(C11 - C11f)  if country=="GER"  & partyn==5
/* GE_cdu:*/ replace s_delta11 = abs(C11 - C11b)  if country=="GER"  & partyn==1 
/* GE_linke:*/ replace s_delta11 = abs(C11 - C11e)  if country=="GER" & partyn==4
/* GE_gre:*/ replace s_delta11 = abs(C11 - C11d)  if country=="GER"  & partyn==3
/* CA_dem:*/ replace s_delta11 = abs(C11 - C11e)   if country=="CAN"  & partyn==4
/* CA_lib:*/ replace s_delta11 = abs(C11 - C11d)  if country=="CAN"  & partyn==3
/* CA_con:*/ replace s_delta11 = abs(C11 - C11c)  if country=="CAN"  & partyn==2
/* DE_people:*/ replace s_delta11 = abs(C11 - C11c)  if country=="DEN"  & partyn==2
/* DE_redgreen:*/ replace s_delta11 = abs(C11 - C11g)  if country=="DEN"  & partyn==6
/* DE_socpeo:*/ replace s_delta11 = abs(C11 - C11i)  if country=="DEN" & partyn==8
/* DE_lib:*/ replace s_delta11 = abs(C11 - C11e) if country=="DEN" & partyn==4
/* DE_socdem:*/ replace s_delta11 = abs(C11 - C11h)  if country=="DEN"  & partyn==7

//gen stacked PID
gen party01 = 0
/* US_dem:*/ recode party01 (0=1)  if country=="US" & party_10==1 & partyn==1
/* US_rep:*/ recode party01 (0=1)  if country=="US" & party_32==1 & partyn==2
/* UK_lab:*/ recode party01 (0=1)  if country=="UK" & party_16==1 & partyn==2
/* UK_con:*/ recode party01 (0=1)  if country=="UK"  & party_7==1 & partyn==1
/* UK_ukip:*/ recode party01 (0=1)  if country=="UK" & party_40==1 & partyn==7
/* UK_gre:*/ recode party01 (0=1)  if country=="UK" & party_14==1 & partyn==3
/* FR_ps:*/ recode party01 (0=1) if country=="FR"  & party_37==1 & partyn==4
/* FR_ump:*/ recode party01 (0=1)  if country=="FR" & party_41==1 & partyn==5
/* FR_fn:*/ recode party01 (0=1)  if country=="FR"  & party_24==1 & partyn==3
/* FR_gau:*/ recode party01 (0=1)  if country=="FR"  & party_17==1 & partyn==2
/* FR_gre:*/ recode party01 (0=1)  if country=="FR"  & party_15==1 & partyn==6
/* IT_pd:*/ recode party01 (0=1)  if country=="IT"  & party_29==1 & partyn==1
/* IT_m5s:*/ recode party01 (0=1) if country=="IT" & party_12==1 & partyn==3
/* IT_fi:*/ recode party01 (0=1)  if country=="IT" & party_13==1 & partyn==2
/* IT_ln:*/ recode party01 (0=1)  if country=="IT"  & party_19==1 & partyn==4
/* IT_sel:*/ recode party01 (0=1) if country=="IT"  & party_18==1 & partyn==5
/* GE_spd:*/ recode party01 (0=1)  if country=="GER"  & party_33==1 & partyn==5
/* GE_cdu:*/ recode party01 (0=1)  if country=="GER"  & party_5==1  & partyn==1
/* GE_linke:*/ recode party01 (0=1)  if country=="GER" & party_38==1 & partyn==4
/* GE_gre:*/ recode party01 (0=1)  if country=="GER"  & party_3==1 & partyn==3
/* CA_dem:*/ recode party01 (0=1)   if country=="CAN"  & party_27==1 & partyn==4
/* CA_lib:*/ recode party01 (0=1)  if country=="CAN"  & party_21==1 & partyn==3
/* CA_con:*/ recode party01 (0=1)  if country=="CAN"  & party_7==1 & partyn==2
/* DE_people:*/ recode party01 (0=1)  if country=="DEN"  & party_8==1 & partyn==2
/* DE_redgreen:*/ recode party01 (0=1)  if country=="DEN"  & party_31==1 & partyn==6
/* DE_socpeo:*/ recode party01 (0=1)  if country=="DEN" & party_36==1 & partyn==8
/* DE_lib:*/ recode party01 (0=1) if country=="DEN" & party_22==1 & partyn==4
/* DE_socdem:*/ recode party01 (0=1)  if country=="DEN"  & party_35==1 & partyn==7

drop if wei==.
encode cou, gen(ncountry)
gen nparty = 100*ncou + partyn
drop if nparty==101 | nparty<110 & nparty>104 | nparty==201  | nparty==203 | nparty==205| nparty==301| nparty==307| nparty==308| nparty==402| nparty==406| nparty==407| nparty==408| nparty==505 | nparty==506| nparty==507| nparty==508| nparty==604| nparty==605| nparty==606| nparty==608| nparty>702

*** gen dummy for in govenrment vs opposition parties
gen ingov = 0
/* US_dem:*/    replace ingov = 1 if country=="US"  & partyn==1 
/* UK_con:*/    replace ingov = 1 if country=="UK"  & partyn==1 
/* FR_ps:*/     replace ingov = 1 if country=="FR"  & partyn==4
/* IT_pd:*/     replace ingov = 1 if country=="IT"  & partyn==1 
/* GE_cdu:*/    replace ingov = 1 if country=="GER" & partyn==1 
/* DE_socdem:*/ replace ingov = 1 if country=="DEN" & partyn==7
/* DE_soclib:*/ replace ingov = 1 if country=="DEN" & partyn==3
/* CA_con:*/    replace ingov = 1 if country=="CAN" & partyn==2

//ANALYSES

//TABLE 4 and TABLE B5
eststo clear
eststo obj_ologit_ncou: ologit  ptv   delta13 delta31 delta22 delta23  delta24 delta14  delta32 delta33 delta41  delta21 delta34  delta11 i.agef sex i.educl i.income4 party01 ingov i.ncou, vce(cluster case)   
eststo sub_ologit_ncou: ologit  ptv  s_delta13 s_delta31 s_delta22 s_delta23  s_delta24 s_delta14  s_delta32 s_delta33 s_delta41 s_delta21 s_delta34  s_delta11 i.agef sex i.educl i.income4 party01 ingov i.ncou, vce(cluster case)        
esttab using "tab_4_and_b5.rtf", replace mtitles star pr2 p wide
//TABLE B6
eststo clear
forvalues cou =1/7 {
eststo obj_ologit_`cou': ologit  ptv   delta13 delta31 delta22 delta23  delta24 delta14  delta32 delta33 delta41  delta21 delta34  delta11 i.agef sex i.educl i.income4 party01 ingov if ncou==`cou', vce(cluster case)   
esttab using "tab_b6.rtf", replace mtitles star pr2 p wide starlevels(+ .1 * .05 ** .01 *** .001)
}
//TABLE B7
eststo clear
forvalues cou =1/7 {
eststo sub_ologit_`cou': ologit  ptv  s_delta13 s_delta31 s_delta22 s_delta23  s_delta24 s_delta14  s_delta32 s_delta33 s_delta41 s_delta21 s_delta34  s_delta11 i.agef sex i.educl i.income4 party01 ingov if ncou==`cou', vce(cluster case)        
esttab using "tab_b7.rtf", replace mtitles  pr2 p wide starlevels(+ .1 * .05 ** .01 *** .001)
}

